<!DOCTYPE html>

<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.19: https://docutils.sourceforge.io/" />

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta http-equiv="x-ua-compatible" content="ie=edge">
    
    <title>3.4.2. 任务依赖建模 &#8212; FunRec 推荐系统 0.0.1 documentation</title>

    <link rel="stylesheet" href="../../_static/material-design-lite-1.3.0/material.blue-deep_orange.min.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/sphinx_materialdesign_theme.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/fontawesome/all.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/fonts.css" type="text/css" />
    <link rel="stylesheet" type="text/css" href="../../_static/pygments.css" />
    <link rel="stylesheet" type="text/css" href="../../_static/basic.css" />
    <link rel="stylesheet" type="text/css" href="../../_static/d2l.css" />
    <script data-url_root="../../" id="documentation_options" src="../../_static/documentation_options.js"></script>
    <script src="../../_static/jquery.js"></script>
    <script src="../../_static/underscore.js"></script>
    <script src="../../_static/_sphinx_javascript_frameworks_compat.js"></script>
    <script src="../../_static/doctools.js"></script>
    <script src="../../_static/sphinx_highlight.js"></script>
    <script src="../../_static/d2l.js"></script>
    <script async="async" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
    <link rel="index" title="Index" href="../../genindex.html" />
    <link rel="search" title="Search" href="../../search.html" />
    <link rel="next" title="3.4.3. 多目标损失融合" href="3.multi_loss_optim.html" />
    <link rel="prev" title="3.4.1. 基础结构演进" href="1.arch.html" /> 
  </head>
<body>
    <div class="mdl-layout mdl-js-layout mdl-layout--fixed-header mdl-layout--fixed-drawer"><header class="mdl-layout__header mdl-layout__header--waterfall ">
    <div class="mdl-layout__header-row">
        
        <nav class="mdl-navigation breadcrumb">
            <a class="mdl-navigation__link" href="../index.html"><span class="section-number">3. </span>精排模型</a><i class="material-icons">navigate_next</i>
            <a class="mdl-navigation__link" href="index.html"><span class="section-number">3.4. </span>多目标建模</a><i class="material-icons">navigate_next</i>
            <a class="mdl-navigation__link is-active"><span class="section-number">3.4.2. </span>任务依赖建模</a>
        </nav>
        <div class="mdl-layout-spacer"></div>
        <nav class="mdl-navigation">
        
<form class="form-inline pull-sm-right" action="../../search.html" method="get">
      <div class="mdl-textfield mdl-js-textfield mdl-textfield--expandable mdl-textfield--floating-label mdl-textfield--align-right">
        <label id="quick-search-icon" class="mdl-button mdl-js-button mdl-button--icon"  for="waterfall-exp">
          <i class="material-icons">search</i>
        </label>
        <div class="mdl-textfield__expandable-holder">
          <input class="mdl-textfield__input" type="text" name="q"  id="waterfall-exp" placeholder="Search" />
          <input type="hidden" name="check_keywords" value="yes" />
          <input type="hidden" name="area" value="default" />
        </div>
      </div>
      <div class="mdl-tooltip" data-mdl-for="quick-search-icon">
      Quick search
      </div>
</form>
        
<a id="button-show-source"
    class="mdl-button mdl-js-button mdl-button--icon"
    href="../../_sources/chapter_2_ranking/4.multi_objective/2.dependency_modeling.rst.txt" rel="nofollow">
  <i class="material-icons">code</i>
</a>
<div class="mdl-tooltip" data-mdl-for="button-show-source">
Show Source
</div>
        </nav>
    </div>
    <div class="mdl-layout__header-row header-links">
      <div class="mdl-layout-spacer"></div>
      <nav class="mdl-navigation">
          
              <a  class="mdl-navigation__link" href="https://funrec-notebooks.s3.eu-west-3.amazonaws.com/fun-rec.zip">
                  <i class="fas fa-download"></i>
                  Jupyter 记事本
              </a>
          
              <a  class="mdl-navigation__link" href="https://github.com/datawhalechina/fun-rec">
                  <i class="fab fa-github"></i>
                  GitHub
              </a>
      </nav>
    </div>
</header><header class="mdl-layout__drawer">
    
          <!-- Title -->
      <span class="mdl-layout-title">
          <a class="title" href="../../index.html">
              <span class="title-text">
                  FunRec 推荐系统
              </span>
          </a>
      </span>
    
    
      <div class="globaltoc">
        <span class="mdl-layout-title toc">Table Of Contents</span>
        
        
            
            <nav class="mdl-navigation">
                <ul>
<li class="toctree-l1"><a class="reference internal" href="../../chapter_preface/index.html">前言</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../chapter_installation/index.html">安装</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../chapter_notation/index.html">符号</a></li>
</ul>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../../chapter_0_introduction/index.html">1. 推荐系统概述</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../../chapter_0_introduction/1.intro.html">1.1. 推荐系统是什么？</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../chapter_0_introduction/2.outline.html">1.2. 本书概览</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../chapter_1_retrieval/index.html">2. 召回模型</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../../chapter_1_retrieval/1.cf/index.html">2.1. 协同过滤</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../chapter_1_retrieval/1.cf/1.itemcf.html">2.1.1. 基于物品的协同过滤</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../chapter_1_retrieval/1.cf/2.usercf.html">2.1.2. 基于用户的协同过滤</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../chapter_1_retrieval/1.cf/3.mf.html">2.1.3. 矩阵分解</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../chapter_1_retrieval/1.cf/4.summary.html">2.1.4. 总结</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../chapter_1_retrieval/2.embedding/index.html">2.2. 向量召回</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../chapter_1_retrieval/2.embedding/1.i2i.html">2.2.1. I2I召回</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../chapter_1_retrieval/2.embedding/2.u2i.html">2.2.2. U2I召回</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../chapter_1_retrieval/2.embedding/3.summary.html">2.2.3. 总结</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../chapter_1_retrieval/3.sequence/index.html">2.3. 序列召回</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../chapter_1_retrieval/3.sequence/1.user_interests.html">2.3.1. 深化用户兴趣表示</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../chapter_1_retrieval/3.sequence/2.generateive_recall.html">2.3.2. 生成式召回方法</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../chapter_1_retrieval/3.sequence/3.summary.html">2.3.3. 总结</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1 current"><a class="reference internal" href="../index.html">3. 精排模型</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="../1.wide_and_deep.html">3.1. 记忆与泛化</a></li>
<li class="toctree-l2"><a class="reference internal" href="../2.feature_crossing/index.html">3.2. 特征交叉</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../2.feature_crossing/1.second_order.html">3.2.1. 二阶特征交叉</a></li>
<li class="toctree-l3"><a class="reference internal" href="../2.feature_crossing/2.higher_order.html">3.2.2. 高阶特征交叉</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../3.sequence.html">3.3. 序列建模</a></li>
<li class="toctree-l2 current"><a class="reference internal" href="index.html">3.4. 多目标建模</a><ul class="current">
<li class="toctree-l3"><a class="reference internal" href="1.arch.html">3.4.1. 基础结构演进</a></li>
<li class="toctree-l3 current"><a class="current reference internal" href="#">3.4.2. 任务依赖建模</a></li>
<li class="toctree-l3"><a class="reference internal" href="3.multi_loss_optim.html">3.4.3. 多目标损失融合</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../5.multi_scenario/index.html">3.5. 多场景建模</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../5.multi_scenario/1.multi_tower.html">3.5.1. 多塔结构</a></li>
<li class="toctree-l3"><a class="reference internal" href="../5.multi_scenario/2.dynamic_weight.html">3.5.2. 动态权重建模</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../chapter_3_rerank/index.html">4. 重排模型</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../../chapter_3_rerank/1.greedy.html">4.1. 基于贪心的重排</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../chapter_3_rerank/2.personalized.html">4.2. 基于个性化的重排</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../chapter_3_rerank/3.summary.html">4.3. 本章小结</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../chapter_4_trends/index.html">5. 难点及热点研究</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../../chapter_4_trends/1.debias.html">5.1. 模型去偏</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../chapter_4_trends/2.cold_start.html">5.2. 冷启动问题</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../chapter_4_trends/3.generative.html">5.3. 生成式推荐</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../chapter_4_trends/4.summary.html">5.4. 本章小结</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../chapter_5_projects/index.html">6. 项目实践</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../../chapter_5_projects/1.understanding.html">6.1. 赛题理解</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../chapter_5_projects/2.baseline.html">6.2. Baseline</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../chapter_5_projects/3.analysis.html">6.3. 数据分析</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../chapter_5_projects/4.recall.html">6.4. 多路召回</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../chapter_5_projects/5.feature_engineering.html">6.5. 特征工程</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../chapter_5_projects/6.ranking.html">6.6. 排序模型</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../chapter_appendix/index.html">7. Appendix</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../../chapter_appendix/word2vec.html">7.1. Word2vec</a></li>
</ul>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../chapter_references/references.html">参考文献</a></li>
</ul>

            </nav>
        
        </div>
    
</header>
        <main class="mdl-layout__content" tabIndex="0">

	<script type="text/javascript" src="../../_static/sphinx_materialdesign_theme.js "></script>
    <header class="mdl-layout__drawer">
    
          <!-- Title -->
      <span class="mdl-layout-title">
          <a class="title" href="../../index.html">
              <span class="title-text">
                  FunRec 推荐系统
              </span>
          </a>
      </span>
    
    
      <div class="globaltoc">
        <span class="mdl-layout-title toc">Table Of Contents</span>
        
        
            
            <nav class="mdl-navigation">
                <ul>
<li class="toctree-l1"><a class="reference internal" href="../../chapter_preface/index.html">前言</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../chapter_installation/index.html">安装</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../chapter_notation/index.html">符号</a></li>
</ul>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../../chapter_0_introduction/index.html">1. 推荐系统概述</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../../chapter_0_introduction/1.intro.html">1.1. 推荐系统是什么？</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../chapter_0_introduction/2.outline.html">1.2. 本书概览</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../chapter_1_retrieval/index.html">2. 召回模型</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../../chapter_1_retrieval/1.cf/index.html">2.1. 协同过滤</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../chapter_1_retrieval/1.cf/1.itemcf.html">2.1.1. 基于物品的协同过滤</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../chapter_1_retrieval/1.cf/2.usercf.html">2.1.2. 基于用户的协同过滤</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../chapter_1_retrieval/1.cf/3.mf.html">2.1.3. 矩阵分解</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../chapter_1_retrieval/1.cf/4.summary.html">2.1.4. 总结</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../chapter_1_retrieval/2.embedding/index.html">2.2. 向量召回</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../chapter_1_retrieval/2.embedding/1.i2i.html">2.2.1. I2I召回</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../chapter_1_retrieval/2.embedding/2.u2i.html">2.2.2. U2I召回</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../chapter_1_retrieval/2.embedding/3.summary.html">2.2.3. 总结</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../chapter_1_retrieval/3.sequence/index.html">2.3. 序列召回</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../chapter_1_retrieval/3.sequence/1.user_interests.html">2.3.1. 深化用户兴趣表示</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../chapter_1_retrieval/3.sequence/2.generateive_recall.html">2.3.2. 生成式召回方法</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../chapter_1_retrieval/3.sequence/3.summary.html">2.3.3. 总结</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1 current"><a class="reference internal" href="../index.html">3. 精排模型</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="../1.wide_and_deep.html">3.1. 记忆与泛化</a></li>
<li class="toctree-l2"><a class="reference internal" href="../2.feature_crossing/index.html">3.2. 特征交叉</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../2.feature_crossing/1.second_order.html">3.2.1. 二阶特征交叉</a></li>
<li class="toctree-l3"><a class="reference internal" href="../2.feature_crossing/2.higher_order.html">3.2.2. 高阶特征交叉</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../3.sequence.html">3.3. 序列建模</a></li>
<li class="toctree-l2 current"><a class="reference internal" href="index.html">3.4. 多目标建模</a><ul class="current">
<li class="toctree-l3"><a class="reference internal" href="1.arch.html">3.4.1. 基础结构演进</a></li>
<li class="toctree-l3 current"><a class="current reference internal" href="#">3.4.2. 任务依赖建模</a></li>
<li class="toctree-l3"><a class="reference internal" href="3.multi_loss_optim.html">3.4.3. 多目标损失融合</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../5.multi_scenario/index.html">3.5. 多场景建模</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../5.multi_scenario/1.multi_tower.html">3.5.1. 多塔结构</a></li>
<li class="toctree-l3"><a class="reference internal" href="../5.multi_scenario/2.dynamic_weight.html">3.5.2. 动态权重建模</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../chapter_3_rerank/index.html">4. 重排模型</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../../chapter_3_rerank/1.greedy.html">4.1. 基于贪心的重排</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../chapter_3_rerank/2.personalized.html">4.2. 基于个性化的重排</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../chapter_3_rerank/3.summary.html">4.3. 本章小结</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../chapter_4_trends/index.html">5. 难点及热点研究</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../../chapter_4_trends/1.debias.html">5.1. 模型去偏</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../chapter_4_trends/2.cold_start.html">5.2. 冷启动问题</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../chapter_4_trends/3.generative.html">5.3. 生成式推荐</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../chapter_4_trends/4.summary.html">5.4. 本章小结</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../chapter_5_projects/index.html">6. 项目实践</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../../chapter_5_projects/1.understanding.html">6.1. 赛题理解</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../chapter_5_projects/2.baseline.html">6.2. Baseline</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../chapter_5_projects/3.analysis.html">6.3. 数据分析</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../chapter_5_projects/4.recall.html">6.4. 多路召回</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../chapter_5_projects/5.feature_engineering.html">6.5. 特征工程</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../chapter_5_projects/6.ranking.html">6.6. 排序模型</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../chapter_appendix/index.html">7. Appendix</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../../chapter_appendix/word2vec.html">7.1. Word2vec</a></li>
</ul>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../chapter_references/references.html">参考文献</a></li>
</ul>

            </nav>
        
        </div>
    
</header>

    <div class="document">
        <div class="page-content" role="main">
        
  <section id="dependency-modeling">
<span id="id1"></span><h1><span class="section-number">3.4.2. </span>任务依赖建模<a class="headerlink" href="#dependency-modeling" title="Permalink to this heading">¶</a></h1>
<p>前面介绍的多目标方法主要解决任务间的相关性冲突，但现实场景中任务间往往存在明确的依赖关系。用户行为具有天然的时序性：曝光→点击→转化，这种严格的依赖关系带来了新的挑战。</p>
<p>传统方法在处理这种依赖时面临两个核心问题：样本选择偏差（CVR模型在点击样本上训练，却要在全量样本上预测）和数据稀疏性（转化事件极其稀少）。</p>
<p>本节介绍两个全空间建模方法：ESMM解决经典的CTR-CVR联合建模问题，ESM2将思想扩展到更复杂的多阶段行为链路。</p>
<section id="esmm">
<h2><span class="section-number">3.4.2.1. </span>ESMM<a class="headerlink" href="#esmm" title="Permalink to this heading">¶</a></h2>
<figure class="align-default" id="id4">
<span id="esmm-sample-bias"></span><a class="reference internal image-reference" href="../../_images/esmm_sample_bias.png"><img alt="../../_images/esmm_sample_bias.png" src="../../_images/esmm_sample_bias.png" style="width: 300px;" /></a>
<figcaption>
<p><span class="caption-number">图3.4.5 </span><span class="caption-text">点击率和转化率预估的样本空间</span><a class="headerlink" href="#id4" title="Permalink to this image">¶</a></p>
</figcaption>
</figure>
<p>在推荐系统的用户行为链中，存在严格的时序依赖关系。以电商场景为例：</p>
<div class="math notranslate nohighlight" id="equation-chapter-2-ranking-4-multi-objective-2-dependency-modeling-0">
<span class="eqno">(3.4.6)<a class="headerlink" href="#equation-chapter-2-ranking-4-multi-objective-2-dependency-modeling-0" title="Permalink to this equation">¶</a></span>\[\text{曝光(Impression)} \rightarrow \text{点击(Click)} \rightarrow \text{转化(Conversion)}\]</div>
<p>这种链式结构导致两个关键问题：</p>
<ol class="arabic simple">
<li><p>样本选择偏差(Sample Selection
Bias)：传统CVR模型仅在点击样本（CTR正样本）上训练，但线上预估需覆盖全量曝光样本，训练/预估样本分布差异导致泛化能力下降</p></li>
<li><p>数据稀疏性(Data Sparsity)：转化样本量 = 曝光量 × CTR ×
CVR，典型场景：CTR≈2%, CVR≈0.5% →
转化样本仅为曝光的万分之一，稀疏样本难以支撑复杂模型学习</p></li>
</ol>
<p>ESMM (Entire Space Multi-task Model) <span id="id2">(<a class="reference internal" href="../../chapter_references/references.html#id90" title="Ma, X., Zhao, L., Huang, G., Wang, Z., Hu, Z., Zhu, X., &amp; Gai, K. (2018). Entire space multi-task model: an effective approach for estimating post-click conversion rate. The 41st International ACM SIGIR Conference on Research &amp; Development in Information Retrieval (pp. 1137–1140).">Ma <em>et al.</em>, 2018</a>)</span>
通过概率图约束重建任务关系：</p>
<figure class="align-default" id="id5">
<span id="esmm-model-structure"></span><a class="reference internal image-reference" href="../../_images/esmm.png"><img alt="../../_images/esmm.png" src="../../_images/esmm.png" style="width: 400px;" /></a>
<figcaption>
<p><span class="caption-number">图3.4.6 </span><span class="caption-text">ESMM模型结构</span><a class="headerlink" href="#id5" title="Permalink to this image">¶</a></p>
</figcaption>
</figure>
<ul class="simple">
<li><p>输入层：全量曝光样本特征 <span class="math notranslate nohighlight">\(\mathbf{x}\)</span></p></li>
<li><p>共享表征层：基础特征提取模块（原论文中采用的是Shared-Bottom的简单共享结构，也可将其直接替换成MMoE、PLE等复杂的底层共享模型）</p></li>
<li><p>任务塔层：</p>
<ul>
<li><p>CTR Tower：预测点击概率 <span class="math notranslate nohighlight">\(pCTR = f_{ctr}(\mathbf{h})\)</span></p></li>
<li><p>CVR Tower：预测转化概率 <span class="math notranslate nohighlight">\(pCVR = f_{cvr}(\mathbf{h})\)</span></p></li>
</ul>
</li>
<li><p>输出层：</p>
<ul>
<li><p><span class="math notranslate nohighlight">\(pCTR = f_{ctr}(\mathbf{h})\)</span>，<span class="math notranslate nohighlight">\(pCVR = f_{cvr}(\mathbf{h})\)</span>，其中<span class="math notranslate nohighlight">\(pCVR\)</span>不用用来计算Loss</p></li>
<li><p><span class="math notranslate nohighlight">\(pCTCVR = pCTR \times pCVR\)</span>，该值用来计算从曝光空间到转化的Loss</p></li>
</ul>
</li>
</ul>
<p>损失函数的设计：</p>
<div class="math notranslate nohighlight" id="equation-chapter-2-ranking-4-multi-objective-2-dependency-modeling-1">
<span class="eqno">(3.4.7)<a class="headerlink" href="#equation-chapter-2-ranking-4-multi-objective-2-dependency-modeling-1" title="Permalink to this equation">¶</a></span>\[\mathcal{L} = \mathcal{L}_{CTR} + \mathcal{L}_{CTCVR}\]</div>
<p>其中：</p>
<ul>
<li><p><span class="math notranslate nohighlight">\(\mathcal{L}_{CTR}\)</span>
是标准的二分类交叉熵损失，使用全量曝光样本：</p>
<div class="math notranslate nohighlight" id="equation-chapter-2-ranking-4-multi-objective-2-dependency-modeling-2">
<span class="eqno">(3.4.8)<a class="headerlink" href="#equation-chapter-2-ranking-4-multi-objective-2-dependency-modeling-2" title="Permalink to this equation">¶</a></span>\[\mathcal{L}_{CTR} = - \frac{1}{N} \sum_{i=1}^N \left[ y_i^{click} \log(pCTR_i) + (1 - y_i^{click}) \log(1 - pCTR_i) \right]\]</div>
</li>
<li><p><span class="math notranslate nohighlight">\(\mathcal{L}_{CTCVR}\)</span> 是CTCVR任务的交叉熵损失，
通过概率转化公式<span class="math notranslate nohighlight">\(pCTCVR = pCTR \times pCVR\)</span>，<strong>使得CVR
Tower的参数更新是在曝光空间下进行的</strong>：</p>
<div class="math notranslate nohighlight" id="equation-chapter-2-ranking-4-multi-objective-2-dependency-modeling-3">
<span class="eqno">(3.4.9)<a class="headerlink" href="#equation-chapter-2-ranking-4-multi-objective-2-dependency-modeling-3" title="Permalink to this equation">¶</a></span>\[\mathcal{L}_{CTCVR} = - \frac{1}{N} \sum_{i=1}^N \left[ y_i^{click} \cdot y_i^{conv} \log(pCTCVR_i) + (1 - y_i^{click} \cdot y_i^{conv}) \log(1 - pCTCVR_i) \right]\]</div>
</li>
</ul>
<p>ESMM的核心创新在于CVR塔的梯度来源,CVR塔同时接收两种梯度：</p>
<div class="math notranslate nohighlight" id="equation-chapter-2-ranking-4-multi-objective-2-dependency-modeling-4">
<span class="eqno">(3.4.10)<a class="headerlink" href="#equation-chapter-2-ranking-4-multi-objective-2-dependency-modeling-4" title="Permalink to this equation">¶</a></span>\[\nabla_{CVR} = \underbrace{\frac{\partial \mathcal{L}_{CTCVR}}{\partial pCTCVR} \cdot pCTR}_{\text{全空间梯度}} + \underbrace{\frac{\partial \mathcal{L}_{shared}}{\partial \mathbf{h}}}_{\text{共享层梯度}}\]</div>
<p><strong>MMOE代码实践</strong></p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="k">def</span><span class="w"> </span><span class="nf">build_esmm_model</span><span class="p">(</span>
        <span class="n">feature_columns</span><span class="p">,</span>
        <span class="n">task_tower_dnn_units</span><span class="o">=</span><span class="p">[</span><span class="mi">128</span><span class="p">,</span> <span class="mi">64</span><span class="p">],</span>
        <span class="p">):</span>
    <span class="c1"># 1) 输入与嵌入：构建输入层和分组嵌入，拼接为共享 DNN 输入</span>
    <span class="n">input_layer_dict</span> <span class="o">=</span> <span class="n">build_input_layer</span><span class="p">(</span><span class="n">feature_columns</span><span class="p">)</span>
    <span class="n">group_embedding_feature_dict</span> <span class="o">=</span> <span class="n">build_group_feature_embedding_table_dict</span><span class="p">(</span>
        <span class="n">feature_columns</span><span class="p">,</span> <span class="n">input_layer_dict</span><span class="p">,</span> <span class="n">prefix</span><span class="o">=</span><span class="s2">&quot;embedding/&quot;</span>
    <span class="p">)</span>
    <span class="n">dnn_inputs</span> <span class="o">=</span> <span class="n">concat_group_embedding</span><span class="p">(</span><span class="n">group_embedding_feature_dict</span><span class="p">,</span> <span class="s1">&#39;dnn&#39;</span><span class="p">)</span>

    <span class="c1"># 2) 双塔共享底座：同一输入分别走 CTR/CVR 塔，输出各自的 logit</span>
    <span class="n">ctr_logit</span> <span class="o">=</span> <span class="n">DNNs</span><span class="p">(</span><span class="n">task_tower_dnn_units</span> <span class="o">+</span> <span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">name</span><span class="o">=</span><span class="s2">&quot;ctr_dnn&quot;</span><span class="p">)(</span><span class="n">dnn_inputs</span><span class="p">)</span>
    <span class="n">cvr_logit</span> <span class="o">=</span> <span class="n">DNNs</span><span class="p">(</span><span class="n">task_tower_dnn_units</span> <span class="o">+</span> <span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">name</span><span class="o">=</span><span class="s2">&quot;cvr_dnn&quot;</span><span class="p">)(</span><span class="n">dnn_inputs</span><span class="p">)</span>

    <span class="c1"># 3) 概率与联乘：CTR 概率，CVR 概率；CTCVR = CTR × CVR</span>
    <span class="n">ctr_prob</span> <span class="o">=</span> <span class="n">PredictLayer</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s2">&quot;ctr_output&quot;</span><span class="p">)(</span><span class="n">ctr_logit</span><span class="p">)</span>
    <span class="n">cvr_prob</span> <span class="o">=</span> <span class="n">PredictLayer</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s2">&quot;cvr_output&quot;</span><span class="p">)(</span><span class="n">cvr_logit</span><span class="p">)</span>
    <span class="n">ctcvr_prob</span> <span class="o">=</span> <span class="n">tf</span><span class="o">.</span><span class="n">keras</span><span class="o">.</span><span class="n">layers</span><span class="o">.</span><span class="n">Multiply</span><span class="p">()([</span><span class="n">ctr_prob</span><span class="p">,</span> <span class="n">cvr_prob</span><span class="p">])</span>

    <span class="c1"># 4) 构建模型：输入为所有原始输入层，输出为 [CTR, CTCVR]</span>
    <span class="n">model</span> <span class="o">=</span> <span class="n">tf</span><span class="o">.</span><span class="n">keras</span><span class="o">.</span><span class="n">Model</span><span class="p">(</span><span class="n">inputs</span><span class="o">=</span><span class="nb">list</span><span class="p">(</span><span class="n">input_layer_dict</span><span class="o">.</span><span class="n">values</span><span class="p">()),</span> <span class="n">outputs</span><span class="o">=</span><span class="p">[</span><span class="n">ctr_prob</span><span class="p">,</span> <span class="n">ctcvr_prob</span><span class="p">])</span>
    <span class="k">return</span> <span class="n">model</span>
</pre></div>
</div>
<p><strong>训练和评估</strong></p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span><span class="w"> </span><span class="nn">funrec</span><span class="w"> </span><span class="kn">import</span> <span class="n">run_experiment</span>

<span class="n">run_experiment</span><span class="p">(</span><span class="s1">&#39;esmm&#39;</span><span class="p">)</span>
</pre></div>
</div>
<div class="output highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">+----------------+---------------+-------------+-----------------+----------------+--------------+---------------------+--------------------+</span>
<span class="o">|</span>   <span class="n">auc_is_click</span> <span class="o">|</span>   <span class="n">auc_is_like</span> <span class="o">|</span>   <span class="n">auc_macro</span> <span class="o">|</span>   <span class="n">gauc_is_click</span> <span class="o">|</span>   <span class="n">gauc_is_like</span> <span class="o">|</span>   <span class="n">gauc_macro</span> <span class="o">|</span>   <span class="n">val_user_is_click</span> <span class="o">|</span>   <span class="n">val_user_is_like</span> <span class="o">|</span>
<span class="o">+================+===============+=============+=================+================+==============+=====================+====================+</span>
<span class="o">|</span>         <span class="mf">0.5987</span> <span class="o">|</span>        <span class="mf">0.6699</span> <span class="o">|</span>      <span class="mf">0.6343</span> <span class="o">|</span>          <span class="mf">0.5723</span> <span class="o">|</span>          <span class="mf">0.587</span> <span class="o">|</span>       <span class="mf">0.5797</span> <span class="o">|</span>                 <span class="mi">928</span> <span class="o">|</span>                <span class="mi">530</span> <span class="o">|</span>
<span class="o">+----------------+---------------+-------------+-----------------+----------------+--------------+---------------------+--------------------+</span>
</pre></div>
</div>
</section>
<section id="esm2">
<h2><span class="section-number">3.4.2.2. </span>ESM2<a class="headerlink" href="#esm2" title="Permalink to this heading">¶</a></h2>
<p>ESMM成功解决了曝光→点击→转化这一两阶段行为链路的样本偏差问题，但在真实工业场景中，用户行为链路往往更长更复杂。</p>
<figure class="align-default" id="id6">
<span id="esm2-seq"></span><a class="reference internal image-reference" href="../../_images/esm2_seq.png"><img alt="../../_images/esm2_seq.png" src="../../_images/esm2_seq.png" style="width: 250px;" /></a>
<figcaption>
<p><span class="caption-number">图3.4.7 </span><span class="caption-text">用户下单链路图</span><a class="headerlink" href="#id6" title="Permalink to this image">¶</a></p>
</figcaption>
</figure>
<p>如图所示，用户从曝光到转化可能会有非常多条的路径，例如
<code class="docutils literal notranslate"><span class="pre">曝光-&gt;点击-&gt;加入购物车-&gt;购买</span></code>、<code class="docutils literal notranslate"><span class="pre">曝光-&gt;点击-&gt;加入许愿池-&gt;加入购物车-&gt;购买</span></code>等。为了方便后续建模，对点击后的行为分解做了进一步的简化，将加入购物车、加入心愿单归并为决定行为（Deterministic
Action，DAction），将其余行为归并为其他行为（Other Action，OAction）</p>
<figure class="align-default" id="id7">
<span id="esm2-seq-2"></span><a class="reference internal image-reference" href="../../_images/esm2_seq_2.png"><img alt="../../_images/esm2_seq_2.png" src="../../_images/esm2_seq_2.png" style="width: 300px;" /></a>
<figcaption>
<p><span class="caption-number">图3.4.8 </span><span class="caption-text">简化后的用户下单链路图</span><a class="headerlink" href="#id7" title="Permalink to this image">¶</a></p>
</figcaption>
</figure>
<p>为了更好理解后续建模时的数学表达，先对简化后图中的过程，做进一步的数学表示。</p>
<ul class="simple">
<li><p><span class="math notranslate nohighlight">\(y_1=p(\text{点击}|\text{曝光})\)</span></p></li>
<li><p><span class="math notranslate nohighlight">\(y_2=p(\text{决定行为}|\text{点击})\)</span></p></li>
<li><p><span class="math notranslate nohighlight">\(y_3=p(\text{购买}|\text{决定行为})\)</span></p></li>
<li><p><span class="math notranslate nohighlight">\(y_4=p(\text{购买}|\text{其他行为})\)</span></p></li>
</ul>
<p>根据上述定义，更便于理解ESM2模型的结构图：</p>
<figure class="align-default" id="id8">
<span id="esm2-model-structure"></span><a class="reference internal image-reference" href="../../_images/esm2.png"><img alt="../../_images/esm2.png" src="../../_images/esm2.png" style="width: 500px;" /></a>
<figcaption>
<p><span class="caption-number">图3.4.9 </span><span class="caption-text">ESM2模型结构图</span><a class="headerlink" href="#id8" title="Permalink to this image">¶</a></p>
</figcaption>
</figure>
<p>ESM2模型 <span id="id3">(<a class="reference internal" href="../../chapter_references/references.html#id91" title="Wen, H., Zhang, J., Wang, Y., Lv, F., Bao, W., Lin, Q., &amp; Yang, K. (2020). Entire space multi-task modeling via post-click behavior decomposition for conversion rate prediction. Proceedings of the 43rd International ACM SIGIR conference on research and development in Information Retrieval (pp. 2377–2386).">Wen <em>et al.</em>, 2020</a>)</span>
有四个塔，分别用来预测上述的<span class="math notranslate nohighlight">\(y_1,y_2,y_3\)</span>和<span class="math notranslate nohighlight">\(y_4\)</span>，对于这四个塔的输出并不是算4个Loss，而是分别计算<code class="docutils literal notranslate"><span class="pre">曝光-&gt;点击</span></code>、<code class="docutils literal notranslate"><span class="pre">曝光-&gt;决定行为</span></code>和<code class="docutils literal notranslate"><span class="pre">曝光-&gt;购买</span></code>这三个Loss。可以很明显的看出，这三个Loss都是在曝光空间上计算的，和ESMM在曝光空间优化CVR有着异曲同工之处。下面对于上述的三个Loss做简单的介绍，下面的<span class="math notranslate nohighlight">\(BCE_{Loss}\)</span>表示的是二元交叉熵损失。</p>
<p><span class="math notranslate nohighlight">\(L_{ctr}\)</span>点击率预估损失：</p>
<div class="math notranslate nohighlight" id="equation-chapter-2-ranking-4-multi-objective-2-dependency-modeling-5">
<span class="eqno">(3.4.11)<a class="headerlink" href="#equation-chapter-2-ranking-4-multi-objective-2-dependency-modeling-5" title="Permalink to this equation">¶</a></span>\[\begin{split}\begin{aligned}
L_{ctr}
    &amp;= \frac{1}{N} \text{BCE}_{\text{Loss}}(y_{\text{isClick}}^i, \text{pCTR}_i) \\
    &amp; = \frac{1}{N} \text{BCE}_{\text{Loss}}(y_{\text{isClick}}^i, \text{y}_1^i)
\end{aligned}\end{split}\]</div>
<p><span class="math notranslate nohighlight">\(L_{ctavr}\)</span>点击且决定行为概率预估损失：</p>
<div class="math notranslate nohighlight" id="equation-chapter-2-ranking-4-multi-objective-2-dependency-modeling-6">
<span class="eqno">(3.4.12)<a class="headerlink" href="#equation-chapter-2-ranking-4-multi-objective-2-dependency-modeling-6" title="Permalink to this equation">¶</a></span>\[\begin{split}\begin{aligned}
L_{ctavr}
    &amp;= \frac{1}{N} \text{BCE}_{\text{Loss}}(y_{\text{isDAction}}^i, \text{pCTAVR}_i) \\
    &amp; = \frac{1}{N} \text{BCE}_{\text{Loss}}(y_{\text{isDAction}}^i, \text{y}_1^i \cdot \text{y}_2^i)
\end{aligned}\end{split}\]</div>
<p><span class="math notranslate nohighlight">\(L_{ctcvr}\)</span>转化率预估损失：</p>
<div class="math notranslate nohighlight" id="equation-chapter-2-ranking-4-multi-objective-2-dependency-modeling-7">
<span class="eqno">(3.4.13)<a class="headerlink" href="#equation-chapter-2-ranking-4-multi-objective-2-dependency-modeling-7" title="Permalink to this equation">¶</a></span>\[\begin{split}\begin{aligned}
L_{ctcvr}
    &amp;= \frac{1}{N} \text{BCE}_{\text{Loss}}(y_{\text{isPurchuse}}^i, \text{pCTCVR}_i) \\
    &amp; = \frac{1}{N} \text{BCE}_{\text{Loss}}(y_{\text{isPurchuse}}^i, \text{y}_1^i (\text{y}_2^i \cdot \text{y}_3^i + (1 - \text{y}_2^i) \cdot \text{y}_4^i))
\end{aligned}\end{split}\]</div>
<p>从简化后的用户下单链路图中可以看出，用户最终转化是有两条链路的，分别为：</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">曝光-&gt;点击-&gt;决定行为-&gt;购买</span></code>=&gt;<span class="math notranslate nohighlight">\(y_1 \cdot y_2 \cdot y_3\)</span></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">曝光-&gt;点击-&gt;其他行为-&gt;购买</span></code>=&gt;<span class="math notranslate nohighlight">\(y_1 \cdot (1-y_2) \cdot y_4\)</span></p></li>
</ul>
<p>合并上述两条链路的结果就可以得到<span class="math notranslate nohighlight">\(pCTCVR=y_1(y_2 \cdot y_3 + (1-y_2) \cdot y_4)\)</span></p>
<p>最终上述三个损失通过加权融合的方式进行联合优化，</p>
<div class="math notranslate nohighlight" id="equation-chapter-2-ranking-4-multi-objective-2-dependency-modeling-8">
<span class="eqno">(3.4.14)<a class="headerlink" href="#equation-chapter-2-ranking-4-multi-objective-2-dependency-modeling-8" title="Permalink to this equation">¶</a></span>\[L_{final} = w_{ctr} \cdot L_{ctr} +  w_{ctavr} \cdot L_{ctavr} + w_{ctcvr} \cdot L_{ctcvr}\]</div>
<p>其中<span class="math notranslate nohighlight">\(w_{ctr},w_{ctavr},w_{ctcvr}\)</span>分别为三个损失的权重。</p>
<p>ESM2通过这种多阶段的概率乘积方式，将复杂的用户行为链路分解为多个可建模的子任务，同时确保每个任务都在曝光空间中进行联合优化。这种设计不仅有效解决了样本选择偏差问题，还通过共享底层特征表征，降低了数据稀疏性对模型性能的影响。更重要的是，ESM2提供了一种通用的建模思路，可以灵活扩展到更长的行为链路和更多样化的用户决策路径中。</p>
</section>
</section>


        </div>
        <div class="side-doc-outline">
            <div class="side-doc-outline--content"> 
<div class="localtoc">
    <p class="caption">
      <span class="caption-text">Table Of Contents</span>
    </p>
    <ul>
<li><a class="reference internal" href="#">3.4.2. 任务依赖建模</a><ul>
<li><a class="reference internal" href="#esmm">3.4.2.1. ESMM</a></li>
<li><a class="reference internal" href="#esm2">3.4.2.2. ESM2</a></li>
</ul>
</li>
</ul>

</div>
            </div>
        </div>

      <div class="clearer"></div>
    </div><div class="pagenation">
     <a id="button-prev" href="1.arch.html" class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--colored" role="botton" accesskey="P">
         <i class="pagenation-arrow-L fas fa-arrow-left fa-lg"></i>
         <div class="pagenation-text">
            <span class="pagenation-direction">Previous</span>
            <div>3.4.1. 基础结构演进</div>
         </div>
     </a>
     <a id="button-next" href="3.multi_loss_optim.html" class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--colored" role="botton" accesskey="N">
         <i class="pagenation-arrow-R fas fa-arrow-right fa-lg"></i>
        <div class="pagenation-text">
            <span class="pagenation-direction">Next</span>
            <div>3.4.3. 多目标损失融合</div>
        </div>
     </a>
  </div>
        
        </main>
    </div>
  </body>
</html>